<?php
declare(strict_types = 1);
namespace app\api\controller;

use app\api\validate\User;
use app\BaseController;
use think\exception\ValidateException;

class Sms extends BaseController {
    public function code() : object {
        $phoneNumber = input('param.phone_number', '', 'trim');
        $data = ['phone_number'=> $phoneNumber];
        // 也可以使用中间件的方式
        try {
            validate(User::class)->scene('send_code')->check($data);
        } catch (ValidateException $e) {
            return show(config('status.error'), $e->getError());
        }
        if (\app\common\business\Sms::sendCode($phoneNumber, 4, 'jd')) {
            return show(config('status.success'), '发送验证码成功');
        }
        return show(config('status.error'), '发送验证码失败');
    }
}